package com.hc.sss.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.sss.common.ResultMap;
import com.hc.sss.mapper.DictMapper;
import com.hc.sss.pojo.Dict;
import com.hc.sss.service.DictService;

@Service
public class DictServiceImpl implements DictService {

    @Autowired
    private DictMapper dictMapper;

    //添加基础数据
	public int insertDict(Dict dict) {
		return dictMapper.insertDict(dict);
	}

	//查询基础数据详情
	public Dict findDictInfo(Integer dict) {
		return dictMapper.findDictInfo(dict);
	}

	//修改基础数据
	public int updateDict(Dict dict) {
		return dictMapper.updateDict(dict);
	}

	//根据基础数据类型查询
	public List<Dict> findDictByDictTypeList(String dictType) {
		return dictMapper.findDictByDictTypeList(dictType);
	}

	//查询字典信息分页迷糊查询
	public ResultMap<Dict> findDictList(Map<String, Object> paramMap) {
		ResultMap<Dict> resultMap = new ResultMap<Dict>();
		Integer page = 1;
		Integer limit = 5;
		if (paramMap.get("page") != null && !"".equals(paramMap.get("page"))) {
			page = Integer.valueOf(paramMap.get("page").toString());
		}
		if (paramMap.get("limit") != null && !"".equals(paramMap.get("limit"))) {
			limit = Integer.valueOf(paramMap.get("limit").toString());
		}
		PageHelper.startPage(page, limit);
		List<Dict> list = dictMapper.findDictList(paramMap);
		PageInfo<Dict> info = new PageInfo<>(list);
		resultMap.setData(list);
		resultMap.setCount((int)info.getTotal());
		return resultMap;
	}

}
